var tid;
var fid;
var sysId;
var nodeId;
/**
 * 根据主表ID刷新子表表格数据
 */
function reloadDataGridByCid(cid) {
    var url = "platform/aos/commtempletmanagerController/getCommTempletSysCodeSonData.json?cid=" + cid;
    $('#commTempletSysCodeSonDataGrid').datagrid("options").url = url;
    $("#commTempletSysCodeSonDataGrid").datagrid('load', {
        param: null
    });
}

// 刷新子表
function reloadCodeDataGrid() {
    var frow = $('#commTempletSysCodeDataGrid').datagrid('getSelections');
    var cid = frow[0].ID;
    reloadDataGridByCid(cid);
}
/**
 * 转换列类型
 * 
 * @param value
 * @param row
 * @param index
 * @returns
 */
function fomaterColType(value, row, index) {
    if (value == 'string') {
        return  commonLang.dataType.string;//"字符";
    } else if (value == 'integer') {
        return  commonLang.dataType.integer;//"整型";
    } else if (value == 'date') {
        return  commonLang.dataType.date;//"日期";
    }
    return value;
}

/**
 * 转换是否
 * 
 * @param value
 * @param row
 * @param index
 * @returns
 */
function fomaterYn(value, row, index) {
    if (value == 'Y') {
        return commonLang.fomaterType.ifYes;//"是";
    } else {
        return commonLang.fomaterType.ifNo;//"否";
    }
    return value;
}

/**
 * 提交数据
 */
function submitSelest(formName, btnName) {
    var frow = $('#commTempletSysCodeDataGrid').datagrid('getSelections');
    if(frow.length !== 1){
		//commonLang.tip.alert5 "请选择一条数据！"
		alert(commonLang.tip.alert5);
		return false;
	}
    var cid = frow[0].ID;
    $('#' + btnName).linkbutton('disable');
    $.ajax({
        url: 'platform/aos/commtablemanagerController/insertSysCodeData',
        data: {
            cid: cid,
            tid: tid,
            fid: fid
        },
        type: 'post',
        dataType: 'json',
        success: function(result) {
            if (result.flag == "success") {
                parent.reloadDataGridByCid(fid);
                parent.$.messager.show({
                    title:commonLang.tip.alert,//'提示',
                    //commonLang.optip.saveSuccess'保存成功！'
                    msg: commonLang.optip.saveSuccess,
                    timeout: 3000,
                    showType: 'slide'
                });
                closeWindow();
            } else {
                if (result.flag == "failure") {
                    $.messager.show({
                        title: commonLang.tip.alert,//'提示',
                        //commonLang.optip.saveFailure"保存失败！"
                        msg: commonLang.optip.saveFailure,
                        timeout: 2000,
                        showType: 'slide'
                    });
                } else {
                	//commonLang.tip.alert  提示
                    $.messager.alert(commonLang.tip.alert, result.flag, 'warning');
                }
                $('#' + btnName).linkbutton('enable');
            }
        },
        error: function(data, type) {
        	// commonLang.tip.alert 提示  commonLang.optip.err '失败:'
            $.messager.alert(commonLang.tip.alert,commonLang.optip.err, 'warning');
            $('#' + btnName).linkbutton('enable');
        }
    });
}

/**
 * 关闭弹出窗口
 */
function closeWindow() {
    if (parent != null && parent.$('#' + dialogId) != null) {
        parent.$('#' + dialogId).dialog('close');
    }
}


/**
 * 查询子页面回调函数
 */
function searchFieldDataGrid(codeType, codeName) {
    if (codeType != "" && codeType != null) {
        codeType = encodeURI(codeType);
    }
    if (codeName != "" && codeName != null) {
        codeName = encodeURI(codeName);
    }
    var url = 'platform/aos/commtempletmanagerController/getCommTempletSysCodeData.json?codeType=' + codeType + '&codeName=' + codeName;
    $('#commTempletSysCodeDataGrid').datagrid("options").url = url;
    $("#commTempletSysCodeDataGrid").datagrid('load', {
        param: null
    });
    reloadDataGridByCid("@@@");
}
/**
 * 查询按钮
 */
function searchField() {
    var dialogId = "searchSysCodeFormDialog";
    var toActionUrl = "platform/aos/commtempletmanagerController/toTempletSearchSysCodeForm?dialogId=" + dialogId;
    //commonLang.dialog.search参数替换"查询"
    var usdAdd = new CommonDialog(dialogId, "450", "170", toActionUrl, commonLang.dialog.search,
        false, true, false);
    usdAdd.show();
}